package apiday01;

public class SubstringDemo {
    public static void main(String[] args) {
      String name = getName("www.tedu.cn");
      System.out.println(name);
      String str = getName("http://www.google.com");
      System.out.println(str);

       /* String str = "www.tedu.cn";
        String name = str.substring(4,8);
        System.out.println(name);
        name = str.substring(4);
        System.out.println(name);
        */

      /*String str = "www.tedu.cn";
      String name = str.substring(4,8);
      System.out.println(name);
      name = str.substring(4);
      System.out.println(name);
       */



       /* //          01234567890
        String str = "www.tedu.cn";
        String name = str.substring(4,8);
        System.out.println(name);
        name = str.substring(4);
        System.out.println(name);

        */
    }

    /**
     * 获取给定网址中的域名
     * @param line
     * @return
     */
    public static String getName(String line){
      int start = line.indexOf(".")+1;
      int end = line.indexOf(".",start);
      //String str = line.substring(start,end);


       int d1 = line.indexOf(".")+1;
       int d2 = line.indexOf(".",d1);
       String str = line.substring(d1,d2);
       /* int d1 = line.indexOf(".");
        int d2 = line.lastIndexOf(".");
        String str = line.substring(d1+1,d2);

        */

        return str;
    }
}
